{extend name="index_layout"/}
{block name="main"}
<form class="layui-form" method="post">
    {:token()}
    <div class="layui-form-item">
        <label class="layui-form-label">菜单</label>
        <div class="layui-input-block">
            <input type="radio" name="row[ismenu]" value="1" title="是" checked lay-filter="ismenu">
            <input type="radio" name="row[ismenu]" value="0" title="否" lay-filter="ismenu">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上级菜单</label>
        <div class="layui-input-block">
            <select name="row[parentid]" lay-verify="required">
                <option value="0">作为一级菜单</option>
                {$select_categorys|raw}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">规则</label>
        <div class="layui-input-block">
            <input type="text" name="row[name]" lay-verify="required" autocomplete="off"  data-placeholder-node="控制器/方法名,如果有目录请使用 目录名.控制器名/方法名" data-placeholder-menu="父级菜单无需匹配控制器和方法,子级菜单请使用控制器名" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="row[title]" lay-verify="required" autocomplete="off" placeholder="标题" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" data-type="menu">
        <label class="layui-form-label">URL</label>
        <div class="layui-input-block">
            <input type="text" name="row[url]" autocomplete="off" placeholder="url" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标</label>
        <div class="layui-input-block">
            <input type="text" id="iconPicker" lay-filter="iconPicker" class="hide" name="row[icon]">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">规则条件</label>
        <div class="layui-input-block">
            <textarea name="row[condition]" placeholder="规则条件" class="layui-textarea"></textarea>
        </div>
    </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单类型</label>
        <div class="layui-input-block">
            <input type="radio" name="row[menutype]" value="_iframe" title="选项卡(默认)" checked>
            <input type="radio" name="row[menutype]" value="_blank" title="链接">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">扩展属性</label>
        <div class="layui-input-block">
            <textarea name="row[extend]" placeholder="扩展属性" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="row[remark]" placeholder="备注" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示排序</label>
        <div class="layui-input-block">
            <input type="text" name="row[listorder]" autocomplete="off" placeholder="显示排序" class="layui-input" value="0">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否显示</label>
        <div class="layui-input-block">
            <input type="radio" name="row[status]" value="1" title="显示" checked>
            <input type="radio" name="row[status]" value="0" title="隐藏">
        </div>
    </div>
    <div class="layui-form-item layer-footer">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script type="text/javascript">
layui.use(['iconPicker', 'form', 'layer','yznForm'], function() {
    var iconPicker = layui.iconPicker,
        form = layui.form,
        layer = layui.layer,
        $ = layui.$,
        yznForm = layui.yznForm;
        yznForm.bindevent($("form.layui-form"));
        iconPicker.render({
            elem: '#iconPicker4',
            type: 'fontClass'
        });

        iconPicker.render({
            // 选择器，推荐使用input
            elem: '#iconPicker',
            // 数据类型：fontClass/unicode，推荐使用fontClass
            type: 'fontClass',
            // 是否开启搜索：true/false，默认true
            search: true,
            // 是否开启分页：true/false，默认true
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            // 点击回调
            click: function (data) {
                //console.log(data);
            },
            // 渲染成功后的回调
            success: function(d) {
                //console.log(d);
            }
        });

        form.on('radio(ismenu)', function(data){
            var name = $("input[name='row[name]']");
            var ismenu = data.value == 1;
            name.prop("placeholder", ismenu ? name.data("placeholder-menu") : name.data("placeholder-node"));
            $('div[data-type="menu"]').toggleClass("layui-hide", !ismenu);
        })
        $("input[name='row[ismenu]']:checked").next().trigger("click");
});
</script>
{/block}